<style>
    label{ display:inline-block;width: 10%}
</style>
<div class="container-fluid" style="padding: 20px 10px 0px 10px">

    <div class="row-fluid">

        <div class="well">

            <ul class="nav nav-tabs">

                <li class="active"><b>药品编辑</b></li>

            </ul>

            <div id="myTabContent" class="tab-content">

                <div class="tab-pane active in" id="home">

                    <form id="formid" action="/take/take_drug" method="post" style="width: 100%;text-align: left">
                        <input type="hidden" name="id" value="<?=$drugList['id']?>">
                        <input type="hidden" name="take_id" value="<?=I('get.take_id')?>">
                        <input type="hidden" name="submit" value="1">
                        <p><label>所属仓库 : </label>
                            <select name="own_house" id="sel_house">
                                <option value="">请选择</option>
                                <?php if($warehouse){foreach($warehouse as $k=>$v){?>
                                <option value="<?=$v['warehouse_id']?>" <?= $drugList['warehouse'] == $v['warehouse_id']?'selected="selected"':''?> <?=$drugList['warehouse']?'readonly':''?>><?=$v['warehouse_name']?></option>
                                <?php }}?>
                            </select>

                            <label style="padding-left: 28px;">药品名称 : </label>
                            <select name="drug_id" id="drug_id" style="width:219px;" <?=$is_update?'disabled':''?>>
                            <?php if($drugList['drug_id']){?>
                            <option value="<?=$drugMsg['id']?>"><?=$drugMsg['drug_name']?></option>
                            <?php }else{?>
                            <option value="">请选择</option>
                            <?php }?>
                            </select>
                        </p>
                        <p><label>药品编号 : </label>

                            <input type="text" name="drug_no" readonly placeholder="药品编号" value="<?=$drugMsg['drug_no']?>">

                        <label style="padding-left: 28px;">种类 : </label>

                            <input type="text" name="type" readonly placeholder="种类" value="<?=$drugMsg['type']?>"></p>
                        <p><label>规格型号 : </label>

                            <input type="text" name="drug_size" readonly placeholder="规格型号" value="<?=$drugMsg['drug_size']?>">

                            <label style="padding-left: 28px;">单位 : </label>

                            <input type="text" name="drug_unit" readonly placeholder="单位" value="<?=$drugMsg['drug_unit']?>"></p>
                        <p><label>领料部门 : </label>

                            <input type="text" name="take_depart" <?=$take_depart?'readonly':''?> value="<?=$take_depart?>">

                            <label style="padding-left: 28px;">领出量 : </label>

                            <input type="text" id="take_num" name="take_num" <?=$drugList['take_num']?'readonly':''?> value="<?=$drugList['take_num']?>"></p>
                        <p><label>实际用量 : </label>

                            <input type="text" id="realuse_num" <?=$drugList['realuse_num']?'readonly':''?> name="realuse_num" value="<?=$drugList['realuse_num']?>">

                            <label style="padding-left: 28px;">剩余量 : </label>

                            <input type="text" name="last_num" readonly placeholder="剩余量" value="<?=$drugList['last_num']?>"></p>
                        <p><label>报废量 : </label>

                            <input type="text" name="waste_num" <?=$drugList['waste_num']?'readonly':''?> value="<?=$drugList['waste_num']?>">

                            <label style="padding-left: 28px;">瓷娃娃用量 : </label>

                            <input type="text" name="cwwuse_num" <?=$drugList['cwwuse_num']?'readonly':''?> value="<?=$drugList['cwwuse_num']?>"></p>
                        <p>
                            <label>备注 : </label>
                            <textarea style="display:inline; width: 529px; height: 50px;" name="remark"><?=$drugList['remark']?></textarea>

                            </p>


                        <div class="btn-toolbar">
                            <div class="btn-group" style="margin:30px 0 10px 280px;">
                                <input type="submit" name="" value="保存" class="btn btn-primary">
                            </div>
                        </div>
                    </form>

                </div>

            </div>

        </div>

    </div>

    <script>

        $(function(){

            $('#btn-save').click(function(){
                $('#formid').submit();
            });

            $('#realuse_num').on('blur',function() {
                var real_num = $(this).val();
                var take_num = $('#take_num').val();
                if(real_num < 0 || take_num < 0){
                    alert('实际用量和领出量必须为正整数');
                }else{
                    var last_num = parseInt(take_num)-parseInt(real_num);
                    $('input[name=last_num]').val(last_num);
                }
            });

            $('#sel_house').on('change',function() {
                var val = $(this).val();
                $.ajax({
                    url: '/take/onehouse_drug',
                    type: 'POST',
                    dataType: 'json',
                    data: {sel_house: val,type:'药品'},
                })
                .done(function(data) {
                    if(data.code == '0'){
                        $('#drug_id').empty();
                        $('#drug_id').append('<option value="0">请选择</option>');
                        for(item in data.data){
                            $('#drug_id').append('<option value="'+item+'">'+data.data[item]+'</option>');
                        }
                    }else{
                        alert(data.msg);
                    }
                })
            });

            $('#drug_id').on('change',function(){
                var val = $(this).val();
                $.ajax({
                    url: '/drug/getDrugInfo',
                    type: 'POST',
                    dataType: 'json',
                    data: {id: val},
                })
                    .done(function(data) {
                        if(data.code == '0'){
                            $('input[name=type]').val(data.data.type);
                            $('input[name=drug_id]').val(data.data.drug_id);
                            $('input[name=drug_no]').val(data.data.drug_no);
                            $('input[name=drug_size]').val(data.data.drug_size);
                            $('input[name=drug_unit]').val(data.data.drug_unit);
                        }else{
                            alert(data.msg);
                        }
                    })
                    .fail(function() {
                        console.log("error");
                    })
            });
        })

    </script>